package com.car.loan.project.xr.controller;

import com.car.loan.framework.aspectj.lang.annotation.DataStatus;
import com.car.loan.framework.aspectj.lang.annotation.Log;
import com.car.loan.framework.aspectj.lang.enums.BusinessType;
import com.car.loan.framework.web.domain.AjaxResult;
import com.car.loan.project.xr.service.ILoanService;
import com.car.loan.project.xr.service.SettlementService;
import com.car.loan.project.xr.util.bo.business.LoanBaseInfo;
import com.car.loan.project.xr.util.bo.business.SettlementInfoBo;
import com.car.loan.project.xr.util.select.LoanApplySelect;
import com.car.loan.project.xr.util.vo.SettlementInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangding
 * @date 2020/2/16 14:16
 */
@RestController
@RequestMapping("xr/settlement")
@Api(value = "结清信息", tags = "车贷业务-结清信息")
public class SettlementController {

    @Autowired
    private ILoanService loanService;

    @Autowired
    private SettlementService settlementService;

    @PreAuthorize("@ss.hasPermi('loan:settlement:query')")
    @GetMapping("settlement/list")
    @ApiOperation(value = "获取结清信息列表", notes = "状态值为0=未结清1=已结清", response = LoanBaseInfo.class, responseContainer = "list")
    @DataStatus(loanStatusEnum = com.car.loan.common.enums.LoanStatusEnum.SETTLEMENT_INFO_STATUS)
    public AjaxResult settlementList(@Valid LoanApplySelect loanApplySelect) {
        return AjaxResult.success(loanService.page(loanApplySelect));
    }


    @PreAuthorize("@ss.hasPermi('loan:settlement:query')")
    @GetMapping("{loanId}")
    @ApiOperation(value = "获取结清信息详情", response = SettlementInfoVo.class)
    public AjaxResult settlementInfo(@PathVariable Long loanId) {
        return AjaxResult.success(settlementService.getInfo(loanId));
    }


    @PreAuthorize("@ss.hasPermi('loan:settlement:input')")
    @PostMapping("input")
    @Log(title = "结清信息录入", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "结清信息录入")
    public AjaxResult audit(@RequestBody @Valid SettlementInfoBo settlementInfoBo) {
        return settlementService.input(settlementInfoBo);
    }

}
